package com.rainman.noswagger.def_interface;

import com.rainman.noswagger.core.MethodInfoInterface;
import com.rainman.noswagger.info_bean.AnnoInfoBean;
import com.rainman.noswagger.info_bean.MethodInfoBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 默认预处理MethodInfo
 *
 */
public class DefMethodInfoWorker implements MethodInfoInterface {



    @Override
    public List<String> getUrls(MethodInfoBean methodInfoBean) {

        List<String> urls=new ArrayList<>();

        for(AnnoInfoBean annoInfoBean:methodInfoBean.getAnnoInfoBeanList()){

            if("RequestMapping".equals(annoInfoBean.getAnnoName())
                    ||"GetMapping".equals(annoInfoBean.getAnnoName())
                    ||"PostMapping".equals(annoInfoBean.getAnnoName())
                    ||"DeleteMapping".equals(annoInfoBean.getAnnoName())
                    ||"PutMapping".equals(annoInfoBean.getAnnoName())
            ){

                String[] split = annoInfoBean.getFullInfo().split("\"");

                if(split.length<3){
                    continue;
                }
                for(int i=0;i<split.length;i++){
                    if(i%2==1){
                        urls.add(split[i]);
                    }
                }

            }

        }

        return urls;
    }

}
